package dao;

import java.sql.*;
/* akses database */
public class db {
	public Connection dbOpen(){
        String dbname="jdbc:mysql://localhost:3306/simpleapp";
        Connection con =null;
        try{
            Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection(dbname,"root","");
            con.setAutoCommit(false);
            if(con==null)
                System.err.println("Koneksi ke Database gagal");
            else
                System.err.println("Koneksi ke Database berhasil");
        }
        catch(ClassNotFoundException ex){
            System.err.println("Driver Error");
            ex.printStackTrace();
            System.exit(1);
        }
        catch(SQLException ex){
            System.err.println("Tidak berhasil Koneksi");
            System.exit(1);
        }
        return con;
    }
    /*
    public int dbConnect() {
    	int hasil = 0;
        String dbname="jdbc:mysql://localhost:3306/simpleapp";
        Connection con =null;
        try{
            Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection(dbname,"root","");
            con.setAutoCommit(false);
            if(con!=null)
                hasil = 1;
        }
        catch(ClassNotFoundException ex){
            System.err.println("Driver Error");
            ex.printStackTrace();
            System.exit(1);
        }
        catch(SQLException ex){
            System.err.println("Tidak berhasil Koneksi");
            System.exit(1);
        }
        return hasil;
    }*/
    
  /*  public static  void main(String srgv[]) throws Exception{
    	db app=new db();
        app.dbOpen();
    }*/
}
